import AppNode from "../app_node";
import { RegClass } from "../serialize";
import PrefabStr from "./progress.prefab.html?raw"
@RegClass("Progress")
export default class Progress extends AppNode {
    _progress = 0;
    bar: HTMLDivElement = null;
    get progress() {
        return this._progress;
    }
    set progress(val) {
        this._progress = val;
        this.updateProgress();
    }
    // 更新进度条
    updateProgress() {
        this.bar.style.width = this.progress + '%';
        this.bar.textContent = this.progress.toFixed(0) + '%';
    }

    refCtor(refEle: Element): void {
        super.refCtor(refEle);
        if (refEle.hasAttribute("color")) {
            let col = refEle.getAttribute("color");
            let [c1, c2] = col.split("|");
            this.bar.style.backgroundColor = c1;
            this.ele.style.backgroundColor = c2;
        }
        if (refEle.hasAttribute("color")) {
            let col = refEle.getAttribute("color");
            this.bar.style.backgroundColor = col;
        }
    }
    static get __BindPrefab__(): string {
        return PrefabStr;
    }
};